<template>
 <div class="login-container">
   <div class="login-content">
     <img src="../../assets/login-bg.png">
     <div class="login-form">
       <div class="logo">
         <img style="height: 100%; width: 100%"  src="../../assets/logo.png">
       </div>
       <el-form
           ref="ruleFormRef"
           :rules="rules"
           :label-position="'right'"
           label-width="100px"
           :model="loginForm"
           style="max-width: 460px"
       >
         <el-form-item prop="username">
           <el-input class="inputDeep" v-model="loginForm.username" >
             <template #prefix>
               <el-icon :size="18"><User /></el-icon>
             </template>
           </el-input>
         </el-form-item>
         <el-form-item prop="password">
           <el-input class="inputDeep" show-password type="password" v-model="loginForm.password" >
             <template #prefix>
               <el-icon :size="18"><Lock /></el-icon>
             </template>
           </el-input>
         </el-form-item>
         <el-form-item prop="kaptchacode">
           <el-input class="inputDeep"  v-model="loginForm.kaptchacode" >
             <template #prefix>
               <el-icon :size="18"><Postcard /></el-icon>
             </template>
             <template #suffix>
               <img :src="verifyImage" @click="getVerifyCodeData" style="width: 100%; height: 85%">
             </template>
           </el-input>
         </el-form-item>
         <el-form-item>
           <el-switch @change="savePwsChange" size="small" style="--el-switch-on-color: #ffc200;" v-model="isSavePwd" active-text="记住密码"  />
         </el-form-item>
       </el-form>
       <el-button type="warning" :loading="loading" @click="userLogin">登录</el-button>
     </div>
   </div>
 </div>
</template>

<script setup>
import { reactive, ref } from 'vue';
import { User, Lock, Postcard } from '@element-plus/icons-vue';
import { storeToRefs } from 'pinia';
import { useAccountLogin } from './useAccountLogin.js';
import { userStore } from '../../store/user.js';

const user = userStore();
const { isSavePwd, savedPassword } = storeToRefs(user);
const loginForm = reactive({
  username: 'zhangsan',
  password: isSavePwd || window.localStorage.getItem('isSavePwd') ? savedPassword || window.localStorage.getItem('savedPassword') : '123456',
  kaptchacode: null,
});
const rules = reactive({
  username: [
    {
      required: true, message: '请输入用户账号', trigger: 'blur',
    },
  ],
  password: [
    {
      required: true, message: '请输入密码', trigger: 'blur',
    },
  ],
  kaptchacode: [
    {
      required: true, message: '请输入验证码', trigger: 'blur',
    },
  ],
});
const {
  userLogin, savePwsChange, loading, verifyImage, getVerifyCodeData, ruleFormRef,
} = useAccountLogin(loginForm);
</script>

<style scoped lang="css">
.login-container {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  background-color: #333;
  display: flex;
  justify-content: center;
  align-items: center;
}
.login-content{
  width: 1000px;
  height: 474px;
  border-radius: 8px;
  display: flex;
}
.login-form {
  background: #ffffff;
  width: 40%;
  border-radius: 0px 8px 8px 0px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.logo {
  height: 42px;
  display: flex;
  width: 139px;
  justify-content: center;
  align-items: center;
  margin-bottom: 40px;
}
:deep(.el-form-item__content) {
  margin: unset !important;
}

:deep(.el-button) {
  width: 214px;
  border-radius: 17px;
  padding: 11px 20px !important;
  margin-top: 10px;
  font-weight: 500;
  font-size: 14px;
  border: 0;
  background-color: #ffc200;
}

:deep(.el-input__wrapper) {
  box-shadow: 0 1px 0 0 var(--el-input-border-color, var(--el-border-color)) inset,;
  cursor: default;
  border-bottom: 1px solid #e9e9e8;
  border-radius: 0;
  font-size: 14px;
  font-weight: 400;
  color: #333333;
  height: 32px;
  width: 100%;
  line-height: 32px;
}
:deep(.el-input__inner) {
  border: 0;
}
:deep(.el-switch__label.is-active) {
  color:#ffc200;
}

</style>
